package com.ellricky.baselib.ui.order

import android.os.Bundle
import android.view.View
import android.widget.AdapterView
import com.andr.common.http.callback.BaseCallback
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.mvp.BasePresenter
import com.ellricky.baselib.R
import com.ellricky.baselib.cache.LocalCacheUtil
import com.ellricky.baselib.entity.new.ComplainRecord
import com.ellricky.baselib.ui.base.BaseRefreshFragment
import com.ellricky.baselib.ui.order.complain.ComplainDetailActivity
import com.ellricky.baselib.util.EAppUtil
import com.ellricky.baselib.util.NewEBaseCallback
import com.ellricky.baselib.util.NewEListCallback

class ComplainRecordFragment :
    BaseRefreshFragment<Void, BasePresenter<Void>, ComplainRecord>() {

    companion object {
        fun newInstance(): ComplainRecordFragment {
            val fragment = ComplainRecordFragment()
            val bundle = Bundle()
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun initUIView(root: View) {
        super.initUIView(root)
        mTvTitle.setText(R.string.pd_complain_record)
        mIbBack.visibility = View.VISIBLE
        mIbBack.setOnClickListener {
            activity?.finish()
        }
    }

    override fun getRvAdapter(): BaseRecyclerAdapter<ComplainRecord> {
        return ComplainAdapter(mContext)
    }

    override fun getResponseCallback(): BaseCallback? {
        return null
    }

    override fun getResponseCallback2(): NewEBaseCallback {
        return object : NewEListCallback<ComplainRecord>(mContext) {
            override fun onSuccess(data: MutableList<ComplainRecord>?, msg: String?) {
                dataSource = data
                rvView.onLoadFinish(dataSource, refresh)
            }
        }
    }

    override fun initParamMap() {
        super.initParamMap()
        paramMap.put("action", "complainList")
        paramMap.put("school_id", LocalCacheUtil.getSchoolId())
        paramMap.put("eid", LocalCacheUtil.getUid())
    }

    override fun getUrlPath(): String {
        return ""
    }

    override fun onItemClick(adapterView: AdapterView<*>?, view: View?, i: Int, l: Long) {
        super.onItemClick(adapterView, view, i, l)
        EAppUtil.jumpPageWithId(
            mContext, ComplainDetailActivity::class.java, adapter[i].complain_id.toString()
        )
    }
}
